/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.delivery.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.javaeye.delivery.dao.ReasonDAO;
import com.javaeye.delivery.dto.Reason;
import com.javaeye.common.web.ReportData;

public class ReasonService implements IReasonService {
	
	//private static Log log = LogFactory.getLog(ReasonService.class);
	
	private ReasonDAO dao;
	
	public void setDao(ReasonDAO dao) {
		this.dao = dao;
	}
	
	public List<Reason> getReasonList(String orderId) {
		List<Reason> result = dao.getReasonList(orderId);
		return result;
	}
	
	public List<Reason> getReasonList(Date beginDate, Date endDate, int queryDeptId) {
		List<Reason> result;
		if (-1 == queryDeptId) {
			result = dao.getReasonList(beginDate, endDate);
		} else {
			result = dao.getReasonList(beginDate, endDate, queryDeptId);
		}
		return result;
	}
	
	public List<ReportData> getReasonData(Date beginDate, Date endDate) {
		List<ReportData> result = new ArrayList<ReportData>();
		ReportData data;
		for (int i = 1; i < 6; i++) {
			data = new ReportData();
			data.setColumn(Reason.getCategoryString(i));
			long count = dao.getReasonCount(beginDate, endDate, i);
			data.setData(count);
			result.add(data);
		}
		return result;
	}
}
